<template>
  <div class="app-container">

    <u-page title="美陈需求单明细">

      <u-filtered>
        <el-form :inline="true" :model="listQuery" class="search-form">
          <el-form-item label="申请时间" prop="inputDateRange">
            <u-date-time-picker v-model="inputDateRange" />
          </el-form-item>
          <el-form-item label="归档时间" prop="inputDateRange2">
            <u-date-time-picker v-model="inputDateRange2" />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="listQuery.status" placeholder="请选择状态" class="status" clearable>
              <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleFilter">查询</el-button>
          </el-form-item>
        </el-form>
      </u-filtered>

      <u-table
        :data="list"
        :loading="listLoading"
        :options="listOptions"
        :columns="columns"
        :pagination.sync="listQuery"
        :fetch="hdlList"
        @selection-change="hdlSelectChange"
      >
      </u-table>

    </u-page>
  </div>
</template>
<script>
export default {
  data() {
    return {
      api: this.$u.api.ContractFormdata,
      statusList: [{ value: '流转中', label: '流转中' }, { value: '签核完成', label: '签核完成' }],
      // 表格
      columns: [
        {
          prop: 'code',
          label: '表单号'
        },
        {
          prop: 'itemtype',
          label: '物料类型'
        },
        {
          prop: 'applicantnickname',
          label: '申请人'
        },
        {
          prop: 'status',
          label: '当前状态',
          render: (h, params) => {
            if (params.row.status === '流转中') {
              return h('el-tag', { props: { type: 'warning' }}, '流转中')
            } else if (params.row.status === '签核完成') {
              return h('el-tag', { props: { type: 'success' }}, '签核完成')
            }
          }
        },
        {
          prop: 'starttime',
          label: '申请时间'
        },
        {
          prop: 'endtime',
          label: '归档时间'
        },
        {
          prop: 'deptid',
          label: '课室编号'
        },
        {
          prop: 'deptname',
          label: '课室'
        },
        {
          prop: 'firmcode',
          label: '厂编'
        },
        {
          prop: 'firmname',
          label: '厂商'
        },
        {
          prop: 'hth',
          label: '合同号'
        },
        {
          prop: 'zgid',
          label: '专柜代码'
        },
        {
          prop: 'zgname',
          label: '专柜名称'
        },
        {
          prop: 'contracttype',
          label: '承担方式'
        },
        {
          prop: 'paytype',
          label: '支付方式'
        },
        {
          prop: 'summoney',
          label: '总金额'
        },
        {
          prop: 'popname',
          label: '名称'
        },
        {
          prop: 'poptype',
          label: '规格'
        },
        {
          prop: 'floor',
          label: '楼层'
        },
        {
          prop: 'amount',
          label: '单价'
        },
        {
          prop: 'processcount',
          label: '数量'
        },
        {
          prop: 'total',
          label: '总计'
        }
      ],
      list: [],
      inputDateRange: [],
      inputDateRange2: [],
      listLoading: false,
      listOptions: {
        mutiSelect: true,
        stripe: true
      },
      listQuery: {
        page: 1,
        pageSize: 50,
        totalCount: 1,
        status: ''
      }
    }
  },
  mounted() {
    this.getApplicant()
  },
  methods: {
    // 加载申请人员
    getApplicant() {
      const self = this
      self.api.applicant().then(res => {
        self.listQuery.applicantusername = res.data.username
      })
    },
    // 搜索事件
    handleFilter() {
      this.inputdateFormat()
      this.hdlFilter()
    },
    // 注册时间格式转换
    inputdateFormat() {
      if (this.inputDateRange) {
        this.listQuery.beginTime = this.inputDateRange[0]
        this.listQuery.endTime = this.inputDateRange[1]
      } else {
        this.listQuery.beginTime = ''
        this.listQuery.endTime = ''
      }
      if (this.inputDateRange2) {
        this.listQuery.beginTimeByEnd = this.inputDateRange2[0]
        this.listQuery.endTimeByEnd = this.inputDateRange2[1]
      } else {
        this.listQuery.beginTimeByEnd = ''
        this.listQuery.endTimeByEnd = ''
      }
    },
    /**
     * 查询事件
     */
    hdlFilter() {
      this.listQuery.page = 1
      this.hdlList()
    },
    /**
     * 获取列表数据
     */
    hdlList() {
      const self = this
      // 打开加载状态
      self.listLoading = true
      self.api.popdetails(self.listQuery).then(res => {
        // 获取分页列表数据
        self.list = res.data.list
        // 获取分页数据,总页数
        self.listQuery.totalCount = res.data.totalCount
        // 关闭加载状态
        setTimeout(() => {
          self.listLoading = false
        }, 0.5 * 1000)
      })
    },
    /**
     * 跳转申请表单页面
     * @param row
     */
    toform(row) {
      this.$router.push({ path: '/contract/template/ledapply', query: { formcode: row.code }})
    }
  }
}
</script>
<style>
.el-select .el-input {
  width: 220px;
}
</style>
<style lang="scss" scoped>
.app-container{
  .item >>> .el-form-item__content {
    display: flex;
  }
  .status {
    ::v-deep{
      .el-input{
        width: 140px;
      }
    }
  }
  ::v-deep{
    .el-table-expand {
      font-size: 0;

      label {
        width: 90px;
        color: #99a9bf;
        font-size: 12px;
      }

      .el-form-item{
        margin-bottom: 2px;
        margin-right: 0;
        vertical-align: top;
      }

      .el-form-item__content {
        margin-right: 0;
        margin-bottom: 0;
        font-size: 12px;
        display: inline-block;
        vertical-align: top;
        position: relative;
      }
    }
  }
}
</style>
